package com.zzh.jetpackdemo.ctrip

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.zzh.jetpackdemo.R
import kotlinx.android.synthetic.main.activity_ctrip.*
import kotlinx.coroutines.*

class CtripActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_ctrip)
        var tag = 0
        getNetData.setOnClickListener {
//            runBlocking{
                GlobalScope.launch(Dispatchers.Main) {
                    getNetData.isClickable = false
                    var netValue = GlobalScope.async(Dispatchers.IO) {
                        delay(2000)
                        return@async "网络数据${tag}"
                    }.await()
                    tag++
                    content.text = netValue
                    getNetData.isClickable = true
                }
//            }
        }
    }

}